package hn.cch.pattern.strategy;


// 策略接口
interface Strategy {
    void execute();
}

// 具体策略A
class StrategyA implements Strategy {
    @Override
    public void execute() {
        System.out.println("Executing Strategy A");
    }
}

// 具体策略B
class StrategyB implements Strategy {
    @Override
    public void execute() {
        System.out.println("Executing Strategy B");
    }
}

// 上下文类
class Context {
    private Strategy strategy;

    public Context(Strategy strategy) {
        this.strategy = strategy;
    }

    public void executeStrategy() {
        strategy.execute();
    }
}


public class StrategyPattern {

    public static void main(String[] args) {
        Context context = new Context(new StrategyA());
        context.executeStrategy();  // 输出: Executing Strategy A

        context = new Context(new StrategyB());
        context.executeStrategy();  // 输出: Executing Strategy B
    }
}
